#include "graphsupport/graph/operation/TriangleInequalityCloseOperation.h"

TriangleInequalityCloseOperation::TriangleInequalityCloseOperation( bool checkEnabledInSettings )
	: checkEnabledInSettings( checkEnabledInSettings )
{

}

void runFloydWarshall( Graph & graph )
{
    int n = graph.getVertexCount();
    Graph::AdjMatrixType adjMatr = graph.getAdjacentMatrixArr();
    for(int k = 0; k < n;k++)
    {
        for(int i = 0; i < n;i++)
        {
            for(int j = 0; j < n;j++)
            {
                adjMatr[i][j] = std::min(adjMatr[i][j], adjMatr[i][k] + adjMatr[k][j]);
            }
        }
    }
}

void TriangleInequalityCloseOperation::applyTo( Graph & graph, IOperationSettings & genSettings )
{
	if ( checkEnabledInSettings )
	{
		if ( !genSettings.triangleIneqEnabled )
		{
			return;
		}
	}
    runFloydWarshall( graph );
}
